/**
 **************************************************************************************************************************
 * 
 **************************************************************************************************************************
 * @file RBCommon.h
 **************************************************************************************************************************/


#ifndef __RBCOMMON_H__
#define __RBCOMMON_H__


/**************************************************************************************************************************
 * Includes
 **************************************************************************************************************************/
#ifndef WIN32
#define WIN32
#endif

#define RB_USE_MEMORY_MANAGER 0
#include "Foundation/Platform/Types.h"
#include "RBAllocations.h"
#include "RBAssert.h"
#include "RBDelegate.h"

//#include "RBMemoryManagerOff.h"


#include <algorithm>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <hash_set>
#include <hash_map>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <vector>
//#include "RBMemoryManagerOn.h"

#ifndef UNUSED
#define UNUSED(x) ((void*)&x)
#endif


#define STR(s) #s
#define XSTR(s) STR(s)

#define TODO(msg) message (__FILE__ "(" XSTR(__LINE__) ") : TODO: " msg)


#define __RBXJOIN(A,B) A##B
#define RBJOIN(A,B) __RBXJOIN(A,B)

#include "RBRTTI.h"

#include "RBSingleton.h"
#include "RBSmartPointer.h"
#include "RBVector.h"
#include "RBMatrix.h"

#include <Shiny.h>


namespace RBCommon
{
    template<class T> uint32 SafeRelease(T* p)
    {
        if (p)
        {
            return p->Release();
        }
        return 0;
    }

    template<class T> void SafeDecRefCount(T* p)
    {
        if (p)
        {
            p->DecRefCount();
        }
    }
}

inline uint32 bits_set_count(uint32 i)
{
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    return ((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

static const uint16 InvalidHandle = 0xFFFF;

inline bool IsValid(uint16 handle)
{
    return handle != InvalidHandle;
}

#define RBDeclareHandle(Class) class Class; typedef RBHandle<Class> Class##Handle


#if 0
    #define RBDEPRECATED __declspec(deprecated)
#else
    #define RBDEPRECATED
#endif

#ifndef NULL
#define NULL (void*)0
#endif

/**************************************************************************************************************************/

#endif // __RBCOMMON_H__
